< previous page page_167 next page >

Page 167
8160-0167a.gif
Figure 8.3
A 
For...Next loop example.
Examples Filename: ForNext.frm
Heres the syntax:
9f31265bb40b592b1929e18a47ab28e5.gif
For <Counter> = <Start> To <End> [Step <Inc/Decrement>]
    <Statement Block>
Next [<Counter>]
The following example is from the For/Next command button:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdForNext_Click ()
   Dim intLoop As Integer

   Cls
   For intLoop = 1 To 5
      Print intLoop
   Next intLoop
End Sub
For . . . Next Step
The Step clause can be added to the For...Next loop to specify the increment you want to use for the counter variable. The Step clause is listed after the To variable and is followed by a numeric value that can be positive or negative. If the number is negative, make sure the start variable is higher than the end variable.
The following example is from the For/Next Step command button:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdForStep_Click ()
   Dim intLoop As Integer

   Cls
   For intLoop = 10 To 1 Step -1
      Print intLoop
   Next intLoop
End Sub

 
< previous page page_167 next page >

If you like this book, buy it!